/*     */ package openmyexplorer.preferences;
/*     */ 
/*     */ import java.io.File;
/*     */ import java.util.ArrayList;

import openmyexplorer.Activator;
import openmyexplorer.util.Messages;

/*     */ import org.eclipse.jface.preference.IPreferenceStore;
/*     */ import org.eclipse.jface.preference.PreferencePage;
/*     */ import org.eclipse.swt.events.DisposeEvent;
/*     */ import org.eclipse.swt.events.DisposeListener;
/*     */ import org.eclipse.swt.events.ModifyEvent;
/*     */ import org.eclipse.swt.events.ModifyListener;
/*     */ import org.eclipse.swt.events.SelectionAdapter;
/*     */ import org.eclipse.swt.events.SelectionEvent;
/*     */ import org.eclipse.swt.layout.GridData;
/*     */ import org.eclipse.swt.layout.GridLayout;
/*     */ import org.eclipse.swt.widgets.Button;
/*     */ import org.eclipse.swt.widgets.Composite;
/*     */ import org.eclipse.swt.widgets.Control;
/*     */ import org.eclipse.swt.widgets.Event;
/*     */ import org.eclipse.swt.widgets.FileDialog;
/*     */ import org.eclipse.swt.widgets.Group;
/*     */ import org.eclipse.swt.widgets.Label;
/*     */ import org.eclipse.swt.widgets.Text;
/*     */ import org.eclipse.swt.widgets.Widget;
/*     */ import org.eclipse.ui.IWorkbench;
/*     */ import org.eclipse.ui.IWorkbenchPreferencePage;
/*     */ 
/*     */ public class FMPreferencePage extends PreferencePage
/*     */   implements IWorkbenchPreferencePage
/*     */ {
/*  62 */   private ArrayList<Button> fileManagerButtons = new ArrayList();
/*     */   private Label fullPathLabel;
/*     */   private Text fileManagerPath;
/*     */   private Button browseButton;
/*     */   private String selectedFileManager;
/*     */   private String fileManagerPathString;
/*     */ 
/*     */   public void init(IWorkbench workbench)
/*     */   {
/*  81 */     IPreferenceStore store = getPreferenceStore();
/*  82 */     this.selectedFileManager = store
/*  83 */       .getString("linuxFileManager");
/*  84 */     this.fileManagerPathString = store
/*  85 */       .getString("linuxFileManagerPath");
/*  86 */     setDescription(Messages.System_File_Manager_Preferences);
/*     */   }
/*     */ 
/*     */   protected Control createContents(Composite parent)
/*     */   {
/*  91 */     Composite composite = createComposite(parent);
/*  92 */     createMacOSXFMGroup(composite);
/*  93 */     createWindowsFMGroup(composite);
/*  94 */     createLinuxFMGroup(composite);
/*  95 */     return composite;
/*     */   }
/*     */ 
/*     */   protected Composite createComposite(Composite parent) {
/*  99 */     Composite composite = new Composite(parent, 0);
/* 100 */     GridLayout layout = new GridLayout();
/* 101 */     layout.marginWidth = 0;
/* 102 */     layout.marginHeight = 0;
/* 103 */     composite.setLayout(layout);
/* 104 */     composite.setLayoutData(new GridData(272));
/*     */ 
/* 106 */     return composite;
/*     */   }
/*     */ 
/*     */   private Group createGroup(Composite composite, String title) {
/* 110 */     Group groupComposite = new Group(composite, 16384);
/* 111 */     GridLayout layout = new GridLayout();
/* 112 */     groupComposite.setLayout(layout);
/* 113 */     GridData data = new GridData(768);
/*     */ 
/* 115 */     groupComposite.setLayoutData(data);
/* 116 */     groupComposite.setText(title);
/* 117 */     return groupComposite;
/*     */   }
/*     */ 
/*     */   protected void createMacOSXFMGroup(Composite composite) {
/* 121 */     Group groupComposite = createGroup(composite, Messages.MAC_OS_X);
/* 122 */     Button macOSXFMButton = createRadioButton(groupComposite, 
/* 123 */       Messages.Finder, "open");
/* 124 */     macOSXFMButton.setSelection(true);
/*     */   }
/*     */ 
/*     */   protected void createWindowsFMGroup(Composite composite) {
/* 128 */     Group groupComposite = createGroup(composite, Messages.WINDOWS);
/* 129 */     Button windowsFMButton = createRadioButton(groupComposite, 
/* 130 */       Messages.Windows_Explorer, "explorer");
/* 131 */     windowsFMButton.setSelection(true);
/*     */   }
/*     */ 
/*     */   protected void createLinuxFMGroup(Composite composite) {
/* 135 */     Group groupComposite = createGroup(composite, Messages.LINUX);
/*     */ 
/* 137 */     String label = Messages.Nautilus;
/* 138 */     String value = "nautilus";
/* 139 */     createRadioButtonWithSelectionListener(groupComposite, label, value, 
/* 140 */       false);
/*     */ 
/* 142 */     label = Messages.Dolphin;
/* 143 */     value = "dolphin";
/* 144 */     createRadioButtonWithSelectionListener(groupComposite, label, value, 
/* 145 */       false);
/*     */ 
/* 147 */     label = Messages.Thunar;
/* 148 */     value = "thunar";
/* 149 */     createRadioButtonWithSelectionListener(groupComposite, label, value, 
/* 150 */       false);
/*     */ 
/* 152 */     label = Messages.PCManFM;
/* 153 */     value = "pcmanfm";
/* 154 */     createRadioButtonWithSelectionListener(groupComposite, label, value, 
/* 155 */       false);
/*     */ 
/* 157 */     label = Messages.ROX;
/* 158 */     value = "rox";
/* 159 */     createRadioButtonWithSelectionListener(groupComposite, label, value, 
/* 160 */       false);
/*     */ 
/* 162 */     label = Messages.Xdg_open;
/* 163 */     value = "xdg-open";
/* 164 */     createRadioButtonWithSelectionListener(groupComposite, label, value, 
/* 165 */       false);
/*     */ 
/* 167 */     label = Messages.Other;
/* 168 */     value = "other";
/* 169 */     createRadioButtonWithSelectionListener(groupComposite, label, value, 
/* 170 */       true);
/*     */ 
/* 172 */     Composite c = new Composite(groupComposite, 0);
/* 173 */     c.setLayoutData(new GridData(768));
/* 174 */     GridLayout layout = new GridLayout(3, false);
/* 175 */     layout.marginWidth = 0;
/* 176 */     c.setLayout(layout);
/*     */ 
/* 178 */     this.fullPathLabel = new Label(c, 0);
/* 179 */     this.fullPathLabel.setText(Messages.Full_Path_Label_Text);
/* 180 */     this.fileManagerPath = new Text(c, 2048);
/* 181 */     if (this.fileManagerPathString != null) {
/* 182 */       this.fileManagerPath.setText(this.fileManagerPathString);
/*     */     }
/* 184 */     this.fileManagerPath.setLayoutData(new GridData(768));
/* 185 */     this.fileManagerPath.addModifyListener(new ModifyListener() {
/*     */       public void modifyText(ModifyEvent e) {
/* 187 */         if (FMPreferencePage.this.fileManagerPath.isEnabled()) {
/* 188 */           String path = FMPreferencePage.this.fileManagerPath.getText();
/* 189 */           if ((path == null) || (path.equals(""))) {
/* 190 */             FMPreferencePage.this.setValid(false);
/* 191 */             FMPreferencePage.this.setErrorMessage(Messages.Error_Path_Cant_be_blank);
/* 192 */             return;
/*     */           }
/* 194 */           File f = new File(path);
/* 195 */           if ((!f.exists()) || (!f.isFile())) {
/* 196 */             FMPreferencePage.this.setValid(false);
/* 197 */             FMPreferencePage.this.setErrorMessage(Messages.Erorr_Path_Not_Exist_or_Not_a_File);
/* 198 */             return;
/*     */           }
/* 200 */           FMPreferencePage.this.setErrorMessage(null);
/* 201 */           FMPreferencePage.this.setValid(true);
/*     */         }
/*     */       }
/*     */     });
/* 206 */     this.browseButton = new Button(c, 8);
/* 207 */     this.browseButton.setText(Messages.Browse_Button_Text);
/* 208 */     this.browseButton.setFont(composite.getFont());
/* 209 */     this.browseButton.addSelectionListener(new SelectionAdapter() {
/*     */       public void widgetSelected(SelectionEvent evt) {
/* 211 */         String newValue = FMPreferencePage.this.browsePressed();
/* 212 */         if (newValue != null)
/* 213 */           FMPreferencePage.this.setFileManagerPath(newValue);
/*     */       }
/*     */     });
/* 217 */     this.browseButton.addDisposeListener(new DisposeListener() {
/*     */       public void widgetDisposed(DisposeEvent event) {
/* 219 */         FMPreferencePage.this.browseButton = null;
/*     */       }
/*     */     });
/* 223 */     if (!"other".equals(this.selectedFileManager)) {
/* 224 */       this.fullPathLabel.setEnabled(false);
/* 225 */       this.fileManagerPath.setEnabled(false);
/* 226 */       this.browseButton.setEnabled(false);
/*     */     }
/*     */ 
/* 229 */     createNoteComposite(composite.getFont(), groupComposite, 
/* 230 */       Messages.Preference_note, 
/* 231 */       Messages.FileManager_need_to_be_installed);
/*     */   }
/*     */ 
/*     */   private void setFileManagerPath(String value) {
/* 235 */     if (this.fileManagerPath != null) {
/* 236 */       if (value == null) {
/* 237 */         value = "";
/*     */       }
/* 239 */       this.fileManagerPath.setText(value);
/*     */     }
/*     */   }
/*     */ 
/*     */   private String browsePressed() {
/* 244 */     File f = new File(this.fileManagerPath.getText());
/* 245 */     if (!f.exists()) {
/* 246 */       f = null;
/*     */     }
/* 248 */     File filePath = getFilePath(f);
/* 249 */     if (filePath == null) {
/* 250 */       return null;
/*     */     }
/*     */ 
/* 253 */     return filePath.getAbsolutePath();
/*     */   }
/*     */ 
/*     */   private File getFilePath(File startingDirectory) {
/* 257 */     FileDialog fileDialog = new FileDialog(getShell(), 268439552);
/* 258 */     if (startingDirectory != null) {
/* 259 */       fileDialog.setFilterPath(startingDirectory.getPath());
/*     */     }
/* 261 */     String filePath = fileDialog.open();
/* 262 */     if (filePath != null) {
/* 263 */       filePath = filePath.trim();
/* 264 */       if (filePath.length() > 0) {
/* 265 */         return new File(filePath);
/*     */       }
/*     */     }
/*     */ 
/* 269 */     return null;
/*     */   }
/*     */ 
/*     */   private void toggleOtherTextField(boolean enabled) {
/* 273 */     this.fullPathLabel.setEnabled(enabled);
/* 274 */     this.fileManagerPath.setEnabled(enabled);
/* 275 */     this.browseButton.setEnabled(enabled);
/*     */   }
/*     */ 
/*     */   private Button createRadioButton(Composite parent, String label, String value)
/*     */   {
/* 280 */     Button button = new Button(parent, 16400);
/* 281 */     button.setText(label);
/* 282 */     button.setData(value);
/* 283 */     return button;
/*     */   }
/*     */ 
/*     */   private Button createRadioButtonWithSelectionListener(Composite parent, String label, final String value, final boolean enableOtherTextFieldIfClick)
/*     */   {
/* 289 */     Button button = createRadioButton(parent, label, value);
/* 290 */     if ((value != null) && (value.equals(this.selectedFileManager))) {
/* 291 */       button.setSelection(true);
/*     */     }
/* 293 */     button.addSelectionListener(new SelectionAdapter()
/*     */     {
/*     */       public void widgetSelected(SelectionEvent e) {
/* 296 */         FMPreferencePage.this.selectedFileManager = ((String)e.widget.getData());
/* 297 */         FMPreferencePage.this.toggleOtherTextField(enableOtherTextFieldIfClick);
/* 298 */         if ("other".equals(value)) {
/* 299 */           FMPreferencePage.this.fileManagerPath.notifyListeners(24, new Event());
/*     */         } else {
/* 301 */           FMPreferencePage.this.setValid(true);
/* 302 */           FMPreferencePage.this.setErrorMessage(null);
/*     */         }
/*     */       }
/*     */     });
/* 306 */     this.fileManagerButtons.add(button);
/* 307 */     return button;
/*     */   }
/*     */ 
/*     */   protected IPreferenceStore doGetPreferenceStore()
/*     */   {
/* 317 */     return Activator.getDefault().getPreferenceStore();
/*     */   }
/*     */ 
/*     */   protected void performDefaults()
/*     */   {
/* 327 */     IPreferenceStore store = getPreferenceStore();
/* 328 */     for (Button button : this.fileManagerButtons)
/*     */     {
/* 330 */       if (store.getDefaultString("linuxFileManager")
/* 330 */         .equals((String)button.getData())) {
/* 331 */         button.setSelection(true);
/* 332 */         this.selectedFileManager = ((String)button.getData());
/*     */       } else {
/* 334 */         button.setSelection(false);
/*     */       }
/*     */     }
/* 337 */     this.fileManagerPath
/* 338 */       .setText(store
/* 339 */       .getDefaultString("linuxFileManagerPath"));
/* 340 */     super.performDefaults();
/*     */   }
/*     */ 
/*     */   public boolean performOk()
/*     */   {
/* 350 */     IPreferenceStore store = getPreferenceStore();
/* 351 */     store.setValue("linuxFileManager", 
/* 352 */       this.selectedFileManager);
/* 353 */     store.setValue("linuxFileManagerPath", 
/* 354 */       this.fileManagerPath.getText());
/* 355 */     return super.performOk();
/*     */   }
/*     */ }

/* Location:           F:\Eclipse2020\eclipse\dropins\OpenExplorer_1.5.0.v201108051513.jar
 * Qualified Name:     openexplorer.preferences.FMPreferencePage
 * JD-Core Version:    0.6.2
 */